Prepared report templates - #2300
Draft
Flix6x wants to merge 6 commits into
Draft
Conversation
Hosts can now discover and use ready-made report definitions (reporter class + complete config + parameters skeleton) instead of authoring YAML from scratch: - Two templates ship in flexmeasures/data/templates/reports: energy-costs (ProfitOrLossReporter) and self-consumption (PandasReporter), each with FILL_IN sensor placeholders and a recommended rolling reporting window for recurring use. - `flexmeasures show report-templates` lists them; `--name <name>` prints the full YAML (with comments) to pipe to a file. - `flexmeasures add report` and `flexmeasures add automation --type reports` accept `--template <name>`, using the template as defaults under any --config/--parameters files and other options (user keys win; user-provided timing fields replace the template's window). - Unfilled placeholders produce a clear validation error listing the fields to fill in. Part of #2288 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Rbix8k1JfeUWNXEmHEZVpX
Documentation build overview
142 files changed ·
|
Context: - PR #2300 is stacked on #2297, whose automation, timezone, permission, and CLI validation changes advanced after the template branch diverged. Change: - Merge the updated report-automation branch while preserving prepared-template commands and combining them with the current automation CLI validation and output-scope invariant. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - Combining a prepared template with an existing data source silently discarded the template reporter configuration, while non-object override files crashed during dictionary merging. Change: - Make source and template selection mutually exclusive and route report override files through the shared mapping validator so invalid YAML shapes produce actionable CLI errors. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - The template roundtrip did not exercise output-scope enforcement, competing source selection, malformed override files, or reporting periods without production. Change: - Target the automation's actual output asset and add regressions proving ambiguous inputs are rejected, override files require mappings, and zero production leaves self-consumption undefined. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context: - Prepared templates need explicit guidance for competing stored sources and for self-consumption periods where the denominator is zero. Change: - Document that templates cannot accompany an existing source and that zero production yields an undefined, missing self-consumption value. Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Part of the "Reports as automations" story of #2288: hosts can now discover and use prepared report templates — ready-made report definitions (reporter class + complete config + parameters skeleton) — instead of authoring reporter YAML from scratch.
What's included
Packaged templates (
flexmeasures/data/templates/reports/, shipped in the wheel):energy-costs(ProfitOrLossReporter): energy costs over the reporting window, from a power/energy sensor and a consumption price sensor (costs reported as positive values, vialoss_is_positive).self-consumption(PandasReporter): share of produced energy consumed on-site, from a production and a consumption sensor (elementwisemin(production, consumption)averaged per reporting period, divided by average production).Each template contains
name,description,reporter, a completeconfig, and aparametersskeleton withFILL_INsensor placeholders, plus a recommended rolling reporting window (start-offset: -1D,DB/end-offset: DB) for recurring use.CLI:
flexmeasures show report-templateslists the templates (name, reporter, description);--name <name>prints the full commented YAML, ready to pipe to a file.flexmeasures add report --template <name>andflexmeasures add automation --type reports --template <name>load the template's reporter/config/parameters as defaults. User input wins: an explicit--reporteris kept, top-level keys of--config/--parametersfiles override the template's, and user-provided timing fields (start/end/offsets, in the parameters or as CLI options) replace the template's recommended window as a group.start-offset/end-offset) inside a parameters file now also work forflexmeasures add report(as fallbacks for the CLI options), matching how report automations store their rolling window.Tests (
flexmeasures/cli/tests/test_report_templates.py, 5 tests):show report-templateslists both templates and prints valid YAML per template.add automation --type reports --template self-consumptionwith a parameters file that fills the sensors creates a working automation: running it queues a reporting job, and a worker computes and stores the expected daily self-consumption shares.--templateon non-report automations produce clear errors.Docs: new "Report templates" section in
documentation/features/reporting.rst, CLI changelog bullets, and ashow report-templatesrow in the commands overview.Packaging note: verified that the YAML templates are included in the built wheel (hatchling ships all files under the
flexmeasurespackage); no MANIFEST/package-data changes needed.🤖 Generated with Claude Code
https://claude.ai/code/session_01Rbix8k1JfeUWNXEmHEZVpX